package com.xh.bussiness.practice.service.impl;

import com.xh.bussiness.practice.bean.request.PracticeCommonCommentRequest;
import com.xh.bussiness.practice.model.PracticeCommonComment;
import com.xh.bussiness.practice.dao.PracticeCommonCommentMapper;
import com.xh.bussiness.practice.service.IPracticeCommonCommentService;
import com.xh.core.service.impl.BaseServiceImpl;
import com.xh.core.util.UserUtils;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xh.core.bean.XhPage;
import java.util.List;
/**
 * <p>
 * 作业批改常用语库 服务实现类
 * </p>
 *
 * @author Jqm
 * @since 2021-04-29
 */
@Service
public class PracticeCommonCommentServiceImpl extends BaseServiceImpl<PracticeCommonCommentMapper, PracticeCommonComment> implements IPracticeCommonCommentService {

    @Override
    public boolean add(PracticeCommonComment commonComment) {
        return this.insert(commonComment);
    }

    @Override
    public boolean deleteComment(String id) {
        return this.dao.deleteComment(id)>0;
    }

    @Override
    public XhPage queryPracticeCommonCommentPage(XhPage page, PracticeCommonCommentRequest bean) {
        QueryWrapper qw=new QueryWrapper<PracticeCommonComment>();
        //拼装条件
        qw=prepareParams(bean, qw);

        return (XhPage) this.dao.selectPage(page,qw);
    }

    @Override
    public List queryPracticeCommonComment(PracticeCommonCommentRequest bean) {
        QueryWrapper qw=new QueryWrapper<PracticeCommonComment>();
        //拼装条件
        qw=prepareParams(bean, qw);

        return this.dao.selectList(qw);
    }


    /**
     * 准备条件
     * @param bean
     * @param qw
     */
    private QueryWrapper prepareParams(PracticeCommonCommentRequest bean, QueryWrapper qw) {
        if(bean.getIds()!=null&&bean.getIds().length>0){
            qw.in("id",bean.getIds());
        }
        qw.eq("user_id",UserUtils.getCurrentUserId());
        return qw;
    }


}
